#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int sum = 0;
        int left = 0;
        int right = 0;
        int n = nums.size();
        int min = n + 1;
        while (left < n) {
            if (sum < target) {
                if (right >= n) {
                    break;
                }
                sum += nums[right++];
            }
            else {
                int len = right - left;
                if (len < min) {
                    min = len;
                }
                sum -= nums[left++];
            }
        }
        if (min == n + 1) {
            return 0;
        }
        else {
            return min;
        }
    }
};
int main() {
    vector<int> v;
    v.push_back(2);
    v.push_back(3);
    v.push_back(1);
    v.push_back(2);
    v.push_back(4);
    v.push_back(3);
    int target = 7;
    Solution s;
    s.minSubArrayLen(target, v);
    return 0;
}